/*
 * @Author: wang.xiao 
 * @Date: 2017-10-24 15:29:33
 * QQ技术交流群: 329065035
*/

/*
*自定义抢地主叫分面板
*/

class RobLanScore extends egret.Sprite {
	// 声明一个数组,存放所有的按钮
	public btnArr = [];
	// 声明静态数组,存放按钮内容;
	public static btnTitle = ['1分', '2分', '3分', '不叫'];

	public constructor() {
		super();
		this.init();
	}

	private init() {
		// 四个按钮

		for (var i: number = 0; i < 4; i++) {
			var btn = new MBtn("primary", Data.getStageW() / 2 - 195 + 100 * i, Data.getStageH() - 275, 90, 40)
			btn.btnText.text = RobLanScore.btnTitle[i];
			btn.btnText.textColor = 0x000000;
			// this.addChild(btn);
			this.btnArr.push(btn);
		}

		// 给按钮注册事件
		for (var i: number = 0; i < this.btnArr.length; i++) {
			var btn: MBtn = this.btnArr[i];
			btn.touchEnabled = true;
			btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tapHandler, this);
		}

	}
	private tapHandler(e: egret.TouchEvent) {

		// 获取点击事件..注册自定义事件
		var robLanScoreTap = new PlayingTapEvent(PlayingTapEvent.PLAYING_TAP_EVENT);
		// 事件的类型为按钮文本的内容
		robLanScoreTap.eventType = e.target.btnText.text;
		robLanScoreTap.obj = this;
		// 触发事件
		SceneManager.getInstance().gamePlayingPanel.dispatchEvent(robLanScoreTap);
		// 点击之后,会立刻隐藏按钮,防止用户再次点击
		if(this.parent){
			this.parent.removeChild(this);
		}
		
	}

	public end() {
		for (var i: number = 0; i < this.btnArr.length; i++) {
			var btn: MBtn = this.btnArr[i];
			btn.touchEnabled = false;
			if (btn.hasEventListener(egret.TouchEvent.TOUCH_TAP)) {
				btn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.tapHandler, this);
			}

		}
	}
}